package com.heima.article.controller;

import com.heima.model.article.entity.ApArticle;
import com.heima.article.service.ApArticleService;
import com.heima.model.articleDto.ArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.ArticleContants;
import com.heima.model.userDto.ArticleHomeDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;

/**
 * 文章基础信息表(ApArticle)表控制层
 *
 * @author makejava
 * @since 2022-04-16 18:01:56
 */
@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {
    /**
     * 服务对象
     */
    @Resource
    private ApArticleService apArticleService;

    @PostMapping( "/save")
    public ResponseResult<Long> save(@RequestBody ArticleDto dto) throws InvocationTargetException, IllegalAccessException {
        return apArticleService.save(dto);
    }

    //**加载首页**
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
    return apArticleService.load(dto,ArticleContants.LOAD_TYPE_MORE);
    }

    //**加载更多**
    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,ArticleContants.LOAD_TYPE_MORE);
    }
    //**加载最新**
    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,ArticleContants.LOAD_TYPE_NEW);
    }

}

